export function getBar (params) {
  let _series = {
    type: 'bar',
    itemStyle: {
      barBorderRadius: 4
    },
    symbolSize: 12
  }
  let series = []
  if (params.data instanceof Array) {
    for (let i = 0; i < params.data.length; i++) {
      series.push(Object.assign({}, _series, {data: params.data[i].data, name: params.data[i].name}))
    }
  }
  var option = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'none'
      },
      textStyle: {
        fontSize: 12
      }
    },
    legend: {
      show: false
    },
    color: ['#4E78F1', '#FF414A', '#EF752D'],
    grid: {
      top: 50,
      bottom: 23,
      left: 40,
      right: 20
    },
    xAxis: {
      type: 'category',
      boundaryGap: true,
      axisTick: {
        show: false
      },
      axisLabel: {
        color: '#111',
        fontSize: 10
      },
      axisLine: {
        lineStyle: {
          color: '#132A52'
        }
      },
      data: params.xAxis
    },
    yAxis: {
      type: 'value',
      name: params.yName,
      nameTextStyle: {
        color: '#1729ff',
        fontSize: 10,
        align: 'left',
        lineHeight: '20'
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        color: '#fff',
        fontSize: 10
      },
      axisLine: {
        lineStyle: {
          color: '#132A52'
        }
      },
      splitLine: {
        show: false
      }
    },
    series: series
  }
  return option
}

export function getPie (params) {
  let legend = []
  if (params.data instanceof Array) {
    for (let i = 0; i < params.data.length; i++) {
      legend.push(params.data[i].name)
    }
  }
  let option = {
    legend: {
      data: legend,
      right: '5',
      bottom: '10',
      orient: 'vertical',
      itemWidth: 15,
      itemHeight: 10,
      borderRadius: 0
    },
    tooltip: {
      trigger: 'item',
      formatter: '{a} <br/>{b} : {c} ({d}%)',
      textStyle: {
        fontSize: 12
      }
    },
    color: ['#4E78F1', '#FF414A', '#EF752D'],
    series: [
      {
        name: params.label,
        type: 'pie',
        radius: ['30%', '55%'],
        label: {
          formatter: '{b} {d}%'
        },
        center: ['50%', '50%'],
        data: params.data,
        emphasis: {
          itemStyle: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        }
      }
    ]
  }
  return option
}

export function getCLine (params) {
  let _series = {
    type: 'line',
    itemStyle: {
      barBorderRadius: 4
    },
    symbolSize: 12
  }
  let series = []
  if (params.data instanceof Array) {
    for (let i = 0; i < params.data.length; i++) {
      series.push(Object.assign({}, _series, {data: params.data[i].data, name: params.data[i].name}))
    }
  }
  var option = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'none'
      },
      textStyle: {
        fontSize: 12
      }
    },
    legend: {
      show: false
    },
    color: ['#4E78F1', '#FF414A', '#EF752D'],
    grid: {
      top: 50,
      bottom: 23,
      left: 40,
      right: 20
    },
    xAxis: {
      type: 'category',
      boundaryGap: true,
      axisTick: {
        show: false
      },
      axisLabel: {
        color: '#111',
        fontSize: 10
      },
      axisLine: {
        lineStyle: {
          color: '#132A52'
        }
      },
      data: params.xAxis
    },
    yAxis: {
      type: 'value',
      name: params.yName,
      nameTextStyle: {
        color: '#1729ff',
        fontSize: 10,
        align: 'left',
        lineHeight: '20'
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        color: '#fff',
        fontSize: 10
      },
      axisLine: {
        lineStyle: {
          color: '#132A52'
        }
      },
      splitLine: {
        show: false
      }
    },
    series: series
  }
  return option
}
